<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>权限模块-角色管理</title>
<script type="text/javascript">
    // 表单提交的路径
    var submitPath = "<%=basePath%>auth/role/";
	// 之前选中的表格行
	var prevSelected = null;
	// 增删改查，分配资源
	function operation(opt) {
		if(verify(opt)){
			var fm = $("#role_form");
			if(opt == "allot"){
				fm.attr("action",submitPath + opt + ".do?pk=" + $("#pkRoleinfo").val());				
			}else{
				fm.attr("action", submitPath + opt + ".do");				
			}
			fm.submit();
		}
	}
	// 将行数据关联到表单
	function bindToForm(row) {
		if (prevSelected != null) {
			$(prevSelected).removeAttr("style");// 恢复样式为默认样式
			$(prevSelected).find("input").attr("checked",false);// checkbox表示没有选中
		}
		prevSelected = row;
		$(row).css("backgroundColor", "#9c6");// 高亮提示选中行	
		$("#rounded-corner input").attr("checked",false);
		$(row).find("input").attr("checked",true);// 同时checkbox表示选中
		
		// 数据绑定
		$("#pkRoleinfo").val($(row).find("td:nth-child(1)").text());
		$("#rolename").val($(row).find("td:nth-child(2)").text());
	}
	// 验证操作
	function verify(opt, msg) {
		switch (opt) {
		case "save":
			if($("#rolename").val() == ""){
				alert("新增的角色名称不能为空");
				return false;
			}
			return true;
		case "update":
			if(prevSelected == null){
				alert("请先在列表中选中要修改的项");
				return false;
			}
			if($("#rolename").val() == ""){
				alert("修改的角色名称不能为空");
				return false;
			}
			return true;
		case "delete":
			if(prevSelected == null){
				alert("请先在列表中选中要删除的项");
				return false;
			}
			return true;
		case "allot":
			if(prevSelected == null){
				alert("请先在列表中选中要分配资源的项");
				return false;
			}
			return true;			
		default:
			return true;
		}
	}
</script>
<%@include file="/WEB-INF/include/head-common.jsp" %>
<style type="text/css">
form span{
	width: 220px;
	display: inline-block;
	margin:2px;
}
form input[type='text'],form select{
	width:120px;
	vertical-align: middle;
}
form .field_label{
	color:#48f;
	display:inline-block;
	width:60px;
}
</style>
</head>
<body>
<div id="main_container">
	<!-- 顶部信息 -->
	<%@include file="/WEB-INF/include/header.jsp" %>    
    <div class="main_content">
    	<!-- 导航菜单 -->
    	<%@include file="/WEB-INF/include/main-menu.jsp" %>
    
    <div class="center_content">  

	<!-- 左边栏内容 -->
    <div class="left_content">
      		<%@include file="/WEB-INF/include/sidebarmenu.jsp" %>
            
    </div>
      
    <!-- 右边框内容 -->
    <div class="right_content">
    	<div class="position">
	    	<div class="position_box">当前位置：<%@include file="/WEB-INF/include/sitemap.jsp" %></div>
	    </div>              
        
    <h2>角色管理</h2> 
                    
  		<div id="operate">
		<form id="role_form" method="post">
			<input type="button" value="新增" onclick="operation('save')" /> 
			<input type="button" value="修改" onclick="operation('update')" /> 
			<input type="button" value="删除" onclick="operation('delete')" /> 
			<input type="button" value="刷新" onclick="operation('refresh')" /> 
			<input type="button" value="分配资源" onclick="operation('allot')" /> 
			<input type="hidden" id="pkRoleinfo" name="pkRoleinfo" /> 
			<span><label class="field_label">角色名称：</label><input id="rolename" name="rolename" type="text" /></span>
			<span><label class="field_label">角色类型：</label>
				  <label><input name="roletype" type="radio" value="1" checked="checked"/>权限角色</label>
				  <label><input name="roletype" type="radio" value="2" />菜单角色</label>
			</span>
		</form>
	</div>
	<table id="rounded-corner">
		<thead>
			<tr>
				<th class="rounded-company">编号</th>
				<th class="rounded">角色名称</th>
				<th class="rounded">角色类型</th>
				<th class="rounded">添加时间</th>
				<th class="rounded-q4">修改时间</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach var="role" items="${list }">
				<tr onclick="bindToForm(this)">
					<td><input type="checkbox"/>${role.pkRoleinfo }</td>
					<td>${role.rolename }</td>
					<td>${role.roletype }-
					<c:choose>
						<c:when test="${role.roletype=='1' }">权限角色</c:when>
						<c:when test="${role.roletype=='2' }">菜单角色</c:when>
						<c:otherwise>错误的数据</c:otherwise>
					</c:choose>
					</td>
					<td>${role.adddatetime }</td>
					<td>${role.moddatetime }</td>
				</tr>
			</c:forEach>
			<c:if test="${totalcount==0}">
			<tr>
				<td colspan="20" align="center">
					未找到相应数据
				</td>
			</tr>
			</c:if>
		</tbody>
	</table>
     
	</div><!-- end of right content-->
            
                    
  </div>   <!--end of center content -->               
                    

    <div class="clear"></div>
    </div> <!--end of main content-->
	
    
    <div class="footer">
    
    	<div class="left_footer">IN ADMIN PANEL | Powered by <a href="http://indeziner.com">INDEZINER</a></div>
    	<div class="right_footer"><a href="http://indeziner.com"><img src="images/indeziner_logo.gif" alt="" title="" border="0" /></a></div>
    
    </div>

</div>		
</body>
</html>
